package com.jn.glide.views;

import android.content.Intent;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jn.glide.R;
import com.jn.glide.adapter.AvatarResultAdapter;
import com.jn.glide.base.BaseActivity;
import com.jn.glide.contract.AvatarContract;
import com.jn.glide.entity.AvatarEntity;
import com.jn.glide.presenter.AvatarPresenter;

import java.util.ArrayList;
import java.util.List;

public class AvatarActivity extends BaseActivity implements AvatarContract.IAvatarView, AvatarResultAdapter.OnItemClickListener {
    private RecyclerView mRecyclerView;
    private AvatarContract.IAvatarPresenter mPresenter;
    private List<AvatarEntity.ResultDTO> mList;
    private AvatarResultAdapter mAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_avatar;
    }

    @Override
    public void init() {
        mPresenter = new AvatarPresenter(this, this);
        mRecyclerView = findViewById(R.id.recycler);
        mPresenter.getData();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mList = new ArrayList<>();
        mAdapter = new AvatarResultAdapter(mList);
        mAdapter.addItemClickListener(this);
        mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    public void showData(AvatarEntity entity) {
        mList = entity.getResult();
        mAdapter.updateData(mList);
    }

    @Override
    public void onHttpLoading(boolean loading) {

    }

    @Override
    public void onHttpFail(String... msg) {

    }

    @Override
    public void onHttpTimeout() {

    }

    @Override
    public void onHttpTokenExpiration() {

    }

    @Override
    public void onItemClick(ArrayList<AvatarEntity.ResultDTO.ListDTO> itemList) {
        Intent intent = new Intent(AvatarActivity.this, AvatarListActivity.class);
        intent.putParcelableArrayListExtra("list", itemList);
        startActivity(intent);
    }
}
